﻿using Shop.Collect;
using Shop.Model.DB;
using Shop.RemoteModel.PageTemplate.Model;
using Shop.Service.Interface;
using WeDonekRpc.Client;
using WeDonekRpc.Model;

namespace Shop.Service.lmpl
{
    internal class PageTemplateService : IPageTemplateService
    {
        private readonly IPageTemplateCollect _Service;

        public PageTemplateService ( IPageTemplateCollect service )
        {
            this._Service = service;
        }

        public long Add ( PageTemplateAdd data )
        {
            return this._Service.Add(data);
        }

        public void Delete ( long id )
        {
            DBPageTemplate source = this._Service.Get(id);
            this._Service.Delete(source);
        }

        public bool Enable ( long id )
        {
            DBPageTemplate source = this._Service.Get(id);
            return this._Service.Enable(source);
        }

        public PageTemplateDto Get ( long id )
        {
            DBPageTemplate source = this._Service.Get(id);
            return source.ConvertMap<DBPageTemplate, PageTemplateDto>();
        }

        public PagingResult<PageTemplateDto> Query ( PageTemplateQuery query, IBasicPage paging )
        {
            PageTemplateDto[] list = this._Service.Query<PageTemplateDto>(query, paging, out int count);
            return new PagingResult<PageTemplateDto>(count, list);
        }

        public bool Set ( long id, PageTemplateSet set )
        {
            DBPageTemplate source = this._Service.Get(id);
            return this._Service.Set(source, set);
        }
    }
}
